package com.tanhua.task;

import cn.hutool.core.date.DateUtil;
import com.tanhua.domain.AnalysisByDay;
import com.tanhua.mapper.AnalysisByDayMapper;
import com.tanhua.mapper.LogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
//@Component
//public class MyTask {
//    @Autowired
//    private LogMapper logMapper;
//    @Autowired
//    private AnalysisByDayMapper analysisByDayMapper;
//
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void analysis() throws ParseException {
//        System.out.println("当前时间："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//        //今天的日期
//        String today = DateUtil.format(new Date(), "yyyy-MM-dd");
//        //昨天的日期
//        String yesterday = DateUtil.yesterday().toString("yyyy-MM-dd");
//        //统计注册用户
//        Integer numRegistered= logMapper.findNumRegistered("0102",today);
//        //统计登录用户
//        Integer numLogin = logMapper.findNumRegistered("0101",today);
//        //统计活跃用户
//        Integer numActive = logMapper.findActive(today);
//        //统计留存用户
//        Integer numRetention1d = logMapper.findNumRetention1d(yesterday,today);
//        AnalysisByDay analysisByDay = new AnalysisByDay();
//        analysisByDay.setNumActive(numActive);
//        analysisByDay.setNumLogin(numLogin);
//        analysisByDay.setNumRegistered(numRegistered);
//        analysisByDay.setNumRetention1d(numRetention1d);
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        Date date = simpleDateFormat.parse(today);
//        analysisByDay.setRecordDate(date);
//        analysisByDay.setCreated(new Date());
//        analysisByDay.setUpdated(new Date());
//        //在tb_analysis_by_day表插入当天的统计数据
//        analysisByDayMapper.insert(analysisByDay);
//    }
//}
